home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Clear / c / Create next >
Text File  |  1995-07-09  |  2KB  |  69 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Clear.c.Create
  12.     Author:  Copyright © 1993,1994 Jason Howat
  13.     Version: 1.01 (13 May 1994)
  14.     Purpose: Allocate memory for a Clear file.
  15.     History: 1.00 (16 Dec 1993)   initial version
  16.              1.01 (13 May 1994)   updated to use Mem_ library
  17. */
  18.  
  19.  
  20. #include <stdlib.h>
  21. #include "DeskLib:Clear.h"
  22. #include "DeskLib:Mem.h"
  23.  
  24. #include "DeskLib:Clear.h"
  25. #include "ClearDefs.h"
  26.  
  27.  
  28.  
  29.  
  30. clear_picture *Clear_Create(unsigned width, unsigned height, unsigned bpp)
  31. {
  32.   clear_picture *temp;
  33.   unsigned      bitmap_size;
  34.   
  35.  
  36.   if((temp = malloc(sizeof(clear_picture))) == NULL)
  37.     return NULL;
  38.  
  39.   temp->creator = clear__creator;
  40.   temp->creatorversion = clear__creatorversion;
  41.   temp->width = width;
  42.   temp->height = height;
  43.   temp->bpp = bpp;
  44.   if(bpp > 8)
  45.   {
  46.     temp->palette = NULL;
  47.     bitmap_size = 3 * width * height;
  48.   }
  49.   else
  50.   {
  51.     if(!Mem_Alloc((void **)&temp->palette, sizeof(palette_entry) * (1 << bpp)))
  52.     {
  53.       free(temp);
  54.       return NULL;
  55.     }
  56.  
  57.     bitmap_size = width * height;
  58.   }
  59.  
  60.   if(!Mem_Alloc((void **)&temp->bitmap, bitmap_size))
  61.   {
  62.     if(temp->palette)
  63.       Mem_Free((void **)temp->palette);
  64.     free(temp);
  65.   }
  66.  
  67.   return temp;
  68. }
  69.